PORT = '5001';
WEB_NAME = "essc_m_wx"

HOST = 'www.lxyuan.net';
APP_NAME = 'essc';
axios.defaults.baseURL = 'http://' + HOST + ':' + PORT + '/' + APP_NAME+'/';
const HOME_HOST = 'http://' + HOST + '/';
const APP_SERVICE = 'service';
const APP_DESKPTOP = 'desktop';
const PAGE_LOGIN = 'login.html'
/*
*use in
*essc_m_wx/desktop/index.html]1446:17
*/
WEB_HOME = HOME_HOST + WEB_NAME


// let cur_url=window.location.href;
// let path=cur_url.split('/')
// let cur_html=path[path.length-1]

//请求拦截
axios.interceptors.request.use(
    config => {
        config.headers["x-requested-with"] = 'XMLHttpRequest';
		config.headers["Token"] = localStorage.getItem('TOKEN');
		config.headers["UserID"] = localStorage.getItem('USERID');
        return config
    },
    error => {
        return Promise.reject(error)
    }
);
// 响应拦截器
axios.interceptors.response.use(
    response => {
        let data = response.data;
        if (data['code'] && data['code'] === -1) {
            throw new Error(response['data']['msg']);
        } else {
			if (data['code'] == 300) {
				//error.message = "授权失效，请重新登录！";
				alert("授权失效，请重新登录！")
				window.parent.location.href=WEB_HOME + '/' + APP_SERVICE + '/' + PAGE_LOGIN;
				
			}
		}
        return data;
    },
    error => {
        if (error && error.response) {
            switch (error.response.status) {
                case 400:
                    error.message = getErrMsg400(error);
                    // error.message = '请求参数错误, 请刷新重试！';
                    break;
                case 401:
                    error.message = '授权失败，请重新登录！';
                    break;
                case 403:
                    error.message = '无权限操作，拒绝访问！';
                    break;
                case 404:
                    error.message = `请求地址不存在`;
                    break;
                case 408:
                    error.message = '请求超时';
                    break;
                case 500:
                    error.message = '服务器内部错误, 请联系管理员！';
                    break;
                case 505:
                    error.message = 'HTTP版本不受支持';
                    break;
                default:
                    error.message = error.response.status + ": 未知错误"
            }
        }
        return Promise.reject(error)
    }
);

function getErrMsg400(err) {
    let msg = "";
    let data = err.response.data;
    for (let key in data) {
        msg += data[key];
    }
    return msg;
}

function deepCopy(Object) {
    return JSON.parse(JSON.stringify(Object));
}

const LOAD_STYLE = {
		  lock: true,
		  text: '加载中...',
		  spinner: 'el-icon-loading',
		  background: 'rgba(0, 0, 0, 0.7)'
		}
